home *** CD-ROM | disk | FTP | other *** search
/ MACD 5 / MACD 5.bin / workbench / wb / czesc_2 / icontoclip / icontoclip.s < prev    next >
Text File  |  1994-04-04  |  23KB  |  1,196 lines

  1. ***************************************************
  2. * IconToClip                                      *
  3. *    by Douglas Nelson                            *
  4. *                                                 *
  5. * Assemble with Macro68                           *
  6. *                                                 *
  7. * Object size = 3598 ($0E0E) bytes                *
  8. * Output file size = 4052 bytes                   *
  9. *                                                 *
  10. ***************************************************
  11.  
  12.     strict
  13.     default    _absolute,_pcrel
  14.     exeobj
  15.     errfile    ram:assem.output
  16.     objfile    ram:I2C.exe
  17.     listfile    ram:listfile
  18.     incpath    mac:includes
  19.     incpath    ram:includes
  20.     macfile    alllibraryoffsets.i
  21.     macfile    dos/dosextens.i
  22.     macfile    exec/alerts.i
  23.     macfile    exec/ports.i
  24.     macfile    intuition/intuition.i
  25.     macfile    libraries/iffparse.i
  26.     macfile    libraries/gadtools.i
  27.     macfile    workbench/workbench.i
  28.     macfile    workbench/startup.i
  29.  
  30. ***** startup
  31.     move.l    sp,(initialSP)
  32.     move.l    d0,d7    ;store dosCmdLen
  33.     movea.l    (4).w,a6
  34.     move.l    a6,(execbase)
  35.  
  36. * open dos
  37.     lea    dosname,a1
  38.     move.l    #37,d0
  39.     jsr    (_LVOOpenLibrary,a6)
  40.     move.l    d0,(dosbase)
  41.     bne.b    gotdos
  42.     move.l    #AG_OpenLib!AO_DOSLib,d7
  43.     jsr    (_LVOAlert,a6)
  44. failexit    tst.l    d7
  45.     bne.b    fail2
  46.     bsr.b    getWbMsg
  47.     bsr.b    replyWbMsg
  48. fail2    moveq    #20,d0    ;FAIL
  49.     rts
  50.  
  51. exit    movea.l    (execbase),a6
  52.     movea.l    (dosbase),a1
  53.     jsr    (_LVOCloseLibrary,a6)
  54.     tst.l    (WBenchMsg)
  55.     beq.b    exit2
  56.     bsr.b    replyWbMsg
  57. exit2    move.l    (rc),d0
  58.     movea.l    (initialSP),sp
  59.     rts
  60.  
  61. * the next two subroutines here appear to allow byte branches
  62.  
  63. replyWbMsg    movea.l    (execbase),a6
  64.     jsr    (_LVOForbid,a6)
  65.     movea.l    (WBenchMsg),a1
  66.     jsr    (_LVOReplyMsg,a6)
  67.     rts
  68.  
  69. getWbMsg    suba.l    a1,a1
  70.     jsr    (_LVOFindTask,a6)
  71.     movea.l    d0,a5
  72.     lea    (pr_MsgPort,a5),a0
  73.     jsr    (_LVOWaitPort,a6)
  74.     lea    (pr_MsgPort,a5),a0
  75.     jsr    (_LVOGetMsg,a6)
  76.     move.l    d0,(WBenchMsg)
  77.     rts
  78.  
  79. gotdos    move.l    #10,(rc)    ;ERROR for early exit
  80.     tst.l    d7    ;dosCmdLen
  81.     beq.b    WBstart
  82.  
  83. * read command line
  84.     lea    template,a0
  85.     move.l    a0,d1
  86.     lea    pathname,a0
  87.     move.l    a0,d2
  88.     moveq    #0,d3    ;no optional RdArgs
  89.     movea.l    (dosbase),a6
  90.     jsr    (_LVOReadArgs,a6)
  91.     move.l    d0,d1
  92.     jsr    (_LVOFreeArgs,a6)
  93.  
  94.     bra    main
  95.  
  96. WBstart
  97.     bsr.b    getWbMsg
  98. * read WBArgs
  99.     movea.l    d0,a2
  100.     movea.l    (sm_ArgList,a2),a2
  101.     move.l    (wa_Lock,a2),d1
  102.     movea.l    (dosbase),a6
  103.     jsr    (_LVOCurrentDir,a6)
  104.     move.l    d0,d7    ;store old dir
  105.  
  106. * open icon.library
  107.     lea    iconname,a1
  108.     move.l    #37,d0
  109.     movea.l    (execbase),a6
  110.     jsr    (_LVOOpenLibrary,a6)
  111.     move.l    d0,(iconbase)
  112.     beq.b    endicon
  113.  
  114. *read ToolTypes
  115.     movea.l    d0,a6
  116.     movea.l    (wa_Name,a2),a0
  117.     jsr    (_LVOGetDiskObject,a6)
  118.     tst.l    d0
  119.     beq.b    closeicon
  120.     movea.l    d0,a2
  121.     movea.l    (do_ToolTypes,a2),a0
  122.     lea    pathnamename,a1
  123.     jsr    (_LVOFindToolType,a6)
  124.     tst.l    d0
  125.     beq.b    checkcolumn
  126.     moveq    #1,d0
  127.     move.l    d0,(pathname)
  128.  
  129. checkcolumn    movea.l    (do_ToolTypes,a2),a0
  130.     lea    columnname,a1
  131.     jsr    (_LVOFindToolType,a6)
  132.     tst.l    d0
  133.     beq.b    checkwindow
  134.     moveq    #1,d0
  135.     move.l    d0,(column)
  136.  
  137. checkwindow    movea.l    (do_ToolTypes,a2),a0
  138.     lea    windowname,a1
  139.     jsr    (_LVOFindToolType,a6)
  140.     tst.l    d0
  141.     beq.b    freediskobj
  142.     moveq    #1,d0
  143.     move.l    d0,(window)
  144.  
  145. freediskobj
  146.     movea.l    (iconbase),a6
  147.     movea.l    a2,a0
  148.     jsr    (_LVOFreeDiskObject,a6)
  149.  
  150. closeicon    movea.l    (iconbase),a1
  151.     movea.l    (execbase),a6
  152.     jsr    (_LVOCloseLibrary,a6)
  153.  
  154. * restore old dir
  155. endicon    move.l    d7,d1
  156.     movea.l    (dosbase),a6
  157.     jsr    (_LVOCurrentDir,a6)
  158.  
  159.  
  160. ***** main program
  161. main    movea.l    (execbase),a6
  162.  
  163.     lea    workbenchname,a1    ;open workbench
  164.     moveq    #37,d0
  165.     jsr    (_LVOOpenLibrary,a6)
  166.     move.l    d0,(workbenchbase)
  167.     beq    cleanup
  168.     lea    intuitionname,a1    ;open intuition
  169.     moveq    #37,d0
  170.     jsr    (_LVOOpenLibrary,a6)
  171.     move.l    d0,(intuibase)
  172.     beq    cleanup
  173.     lea    iffparsename,a1    ;open iffparse
  174.     moveq    #37,d0
  175.     jsr    (_LVOOpenLibrary,a6)
  176.     move.l    d0,(iffparsebase)
  177.     beq    cleanup
  178.     lea    gadtoolsname,a1    ;open gadtools
  179.     moveq    #37,d0
  180.     jsr    (_LVOOpenLibrary,a6)
  181.     move.l    d0,(gadtoolsbase)
  182.     beq    cleanup
  183.     lea    diskfontname,a1    ;open diskfont
  184.     moveq    #37,d0
  185.     jsr    (_LVOOpenLibrary,a6)
  186.     move.l    d0,(diskfontbase)
  187.     beq    cleanup
  188.     lea    graphicsname,a1    ;open gfx
  189.     moveq    #37,d0
  190.     jsr    (_LVOOpenLibrary,a6)
  191.     move.l    d0,(gfxbase)
  192.     beq    cleanup
  193.  
  194. * create our two MsgPorts
  195.     movea.l    (execbase),a6
  196.     jsr    (_LVOCreateMsgPort,a6)
  197.     move.l    d0,(WorkbenchMP)
  198.     beq    cleanup
  199.     jsr    (_LVOCreateMsgPort,a6)
  200.     move.l    d0,(WindowMP)
  201.     beq    cleanup
  202.  
  203. * add item to Tools menu
  204.     moveq    #1,d0
  205.     moveq    #0,d1
  206.     lea    menuname,a0
  207.     movea.l    (WorkbenchMP),a1
  208.     suba.l    a2,a2
  209.     movea.l    (workbenchbase),a6
  210.     jsr    (_LVOAddAppMenuItemA,a6)
  211.     move.l    d0,(appmenuitem)
  212.     beq    cleanup
  213.  
  214. * cleared all obstacles, so set return code to success
  215.     moveq    #0,d0
  216.     move.l    d0,(rc)
  217.  
  218. * store signal masks
  219.     movea.l    (WindowMP),a0
  220.     moveq    #0,d1
  221.     move.b    (MP_SIGBIT,a0),d1
  222.     moveq    #1,d0
  223.     lsl.l    d1,d0
  224.     move.l    d0,(windowsignal)
  225.  
  226.     movea.l    (WorkbenchMP),a0
  227.     moveq    #0,d1
  228.     move.b    (MP_SIGBIT,a0),d1
  229.     moveq    #1,d0
  230.     lsl.l    d1,d0
  231.     move.l    d0,(wbsignal)
  232.  
  233. * calculate union of all signal masks
  234.     or.l    (windowsignal),d0
  235.     or.l    (breaksignal),d0
  236.     move.l    d0,(allsignals)
  237.  
  238. * open window if user specifies
  239.     tst.l    (window)    ;did user ask for window?
  240.     beq.b    eventloop
  241.     bsr    SetupScreen
  242.     tst.l    d0
  243.     beq.b    nowinbeep
  244.     bsr    OpenI2CWindow
  245.     tst.l    d0
  246.     bne.b    eventloop
  247. nowinbeep    movea.l    (intuibase),a6
  248. *    moveq    #0,d0    ;d0 is zero anyway
  249.     jsr    (_LVODisplayBeep,a6)    ;warn that window is not available
  250.  
  251. eventloop    move.l    (allsignals),d0
  252.     movea.l    (execbase),a6
  253.     jsr    (_LVOWait,a6)
  254.     move.l    d0,d7    ;store signal mask
  255.  
  256. * is signal from WorkbenchMP?
  257.     move.l    (wbsignal),d0
  258.     and.l    d7,d0
  259.     beq.b    testwindowsignal
  260.             bsr    HandleAppMsg
  261.  
  262. * is signal from WindowMP?
  263. testwindowsignal
  264.     move.l    (windowsignal),d0
  265.     and.l    d7,d0
  266.     beq.b    testbreaksignal
  267.     bsr    HandleGadget
  268.     tst.l    d0
  269.     beq.b    cleanup    ;user selected QUIT gadget
  270.  
  271. * is signal a CTRL-C?
  272. testbreaksignal
  273.     move.l    (breaksignal),d0
  274.     and.l    d7,d0
  275.     bne.b    cleanup    ;got BREAK signal
  276.  
  277.     bra    eventloop    ;wait for next event
  278.  
  279. * prepare to quit
  280. cleanup    tst.l    (appmenuitem)
  281.     beq    closewindow
  282.  
  283. * clear pending AppMsgs
  284. clearappmsg    movea.l    (WorkbenchMP),a0
  285.     movea.l    (execbase),a6
  286.     jsr    (_LVOGetMsg,a6)
  287.     tst.l    d0    ;did we get a message?
  288.     beq.b    killappmenu
  289.     movea.l    d0,a1
  290.     jsr    (_LVOReplyMsg,a6)
  291.     bra.b    clearappmsg
  292.  
  293.  
  294. * remove Tools menu item; safe to call with NULL pointer
  295. killappmenu    movea.l    (appmenuitem),a0
  296.     movea.l    (workbenchbase),a6
  297.     jsr    (_LVORemoveAppMenuItem,a6)
  298.  
  299. * close window if open
  300. closewindow    bsr    CloseI2CWindow
  301.     bsr    CloseDownScreen
  302.  
  303. * close MsgPorts
  304.     movea.l    (execbase),a6
  305.     move.l    (WindowMP),d0
  306.     beq.b    closeWorkbenchMP
  307.     movea.l    d0,a0
  308.     jsr    (_LVODeleteMsgPort,a6)
  309.  
  310. closeWorkbenchMP
  311.     move.l    (WorkbenchMP),d0
  312.     beq.b    closelibs
  313.     movea.l    d0,a0
  314.     jsr    (_LVODeleteMsgPort,a6)
  315.  
  316. closelibs    move.l    (gfxbase),d0
  317.     beq.b    closediskfont
  318.     movea.l    d0,a1
  319.     jsr    (_LVOCloseLibrary,a6)
  320.  
  321. closediskfont
  322.     move.l    (diskfontbase),d0
  323.     beq.b    closegadtools
  324.     movea.l    d0,a1
  325.     jsr    (_LVOCloseLibrary,a6)
  326.  
  327. closegadtools
  328.     move.l    (gadtoolsbase),d0
  329.     beq.b    closeiffparse
  330.     movea.l    d0,a1
  331.     jsr    (_LVOCloseLibrary,a6)
  332.  
  333. closeiffparse
  334.     move.l    (iffparsebase),d0
  335.     beq.b    closeintui
  336.     movea.l    d0,a1
  337.     jsr    (_LVOCloseLibrary,a6)
  338.  
  339. closeintui    move.l    (intuibase),d0
  340.     beq.b    closeworkbench
  341.     movea.l    d0,a1
  342.     jsr    (_LVOCloseLibrary,a6)
  343.  
  344. closeworkbench
  345.     move.l    (workbenchbase),d0
  346.     beq.b    allclosed
  347.     movea.l    d0,a1
  348.     jsr    (_LVOCloseLibrary,a6)
  349.  
  350. allclosed
  351.     bra    exit
  352.  
  353.  
  354.  
  355. ***** subroutine HandleAppMsg
  356. * returns NULL in d0 if anything fails
  357. HandleAppMsg
  358.     movea.l    (WorkbenchMP),a0
  359.     movea.l    (execbase),a6
  360.     jsr    (_LVOGetMsg,a6)
  361.     move.l    d0,(appmsg)
  362.     beq    endHandleAppMsg
  363.  
  364.     sf    (separate)    ;first name, so no separator
  365.     movea.l    d0,a0
  366.     move.l    (am_ArgList,a0),(arglist)
  367.     move.l    (am_NumArgs,a0),(numargs)
  368.     bne    IconIsHilited
  369.  
  370. * user selected menu with no icons hilited, so open window
  371.     move.l    (I2CWnd),d0
  372.     beq.b    openwindow
  373.  
  374. * window is open so move it to front
  375.     movea.l    d0,a0
  376.     movea.l    (intuibase),a6
  377.     jsr    (_LVOWindowToFront,a6)
  378.     bra    NextAppMsg
  379.  
  380. * must call SetupScreen() each time before opening window, since sneaky user
  381. * may have changed Workbench screen
  382.  
  383. openwindow    bsr    SetupScreen
  384.     tst.l    d0
  385.     beq.b    nowindow
  386.     bsr    OpenI2CWindow
  387.     tst.l    d0
  388.     bne    NextAppMsg    ;window opened successfully
  389.  
  390. nowindow    movea.l    (intuibase),a6
  391. *    moveq    #0,d0    ;d0 is zero anyway
  392.     jsr    (_LVODisplayBeep,a6)      ;warn that window is not available
  393.     bra    NextAppMsg
  394.  
  395.  
  396. IconIsHilited
  397.     tst.l    (column)
  398.     beq.b    lineformat
  399.     move.b    #$A,(separator)    ;separate names with linefeed
  400.     bra.b    tryInitClip
  401.  
  402. lineformat    move.b    #' ',(separator)    ;separate names with space
  403.  
  404.  
  405. tryInitClip    bsr    InitClip
  406.     tst.l    d0
  407.     beq    AbortClip
  408.  
  409. WriteIconsToClip
  410.     tst.l    (numargs)    ;loop while numargs>0
  411.     beq    callCloseClip
  412.  
  413.     tst.b    (separate)    ;is this first write?
  414.     beq.b    writename    ;if yes, no separator needed
  415.  
  416.     lea    separator,a0
  417.     move.l    a0,d0
  418.     bsr    WriteClip
  419.     tst.l    d0    ;did WriteClip succeed?
  420.     beq    AbortClip
  421.  
  422.  
  423. writename    tst.l    (pathname)    ;write full pathname?
  424.     beq    IconNameOnly
  425.  
  426. * write full pathname
  427. * first, get directory path
  428.     movea.l    (arglist),a0
  429.     move.l    (wa_Lock,a0),d1
  430.     lea    dirname,a0
  431.     move.l    a0,d2
  432.     move.l    #256,d3
  433.     movea.l    (dosbase),a6
  434.     jsr    (_LVONameFromLock,a6)
  435.     tst.l    d0
  436.     beq    AbortClip
  437.  
  438. * add filename, if any
  439.     movea.l    (arglist),a0
  440.     movea.l    (wa_Name,a0),a0    ;put ptr to filename in a0
  441.     tst.b    (a0)        ;test if name is non-null
  442.     beq.b    writepathname    ;icon is volume or directory
  443.  
  444. * add filename to directory pathname
  445.     move.l    a0,d2
  446.     lea    dirname,a0
  447.     move.l    a0,d1
  448.     move.l    #256,d3
  449.     movea.l    (dosbase),a6
  450.     jsr    (_LVOAddPart,a6)
  451.     tst.l    d0
  452.     beq    AbortClip
  453.  
  454. writepathname
  455.     lea    dirname,a0
  456.     move.l    a0,d0
  457.     bsr    WriteClip
  458.     tst.l    d0
  459.     beq    AbortClip
  460.     bra    nextarg
  461.  
  462. * write icon name only
  463. * first, is icon a file?
  464. IconNameOnly
  465.     movea.l    (arglist),a1
  466.     movea.l    (wa_Name,a1),a0      ;put ptr to filename in a0
  467.     tst.b    (a0)    ;test if name is non-null
  468.     beq.b    IconIsDir    ;icon is volume or directory
  469.  
  470. * icon is file, so write filename
  471.     move.l    a0,d0
  472.     bsr    WriteClip
  473.     tst.l    d0
  474.     beq    AbortClip
  475.     bra    nextarg
  476.  
  477. * icon is volume or directory; extract its name and write it
  478. IconIsDir    move.l    (wa_Lock,a1),d1
  479.     lea    dirname,a0
  480.     move.l    a0,d2
  481.     move.l    #256,d3
  482.     movea.l    (dosbase),a6
  483.     jsr    (_LVONameFromLock,a6)
  484.     tst.l    d0
  485.     beq    AbortClip
  486.  
  487. * get last element of pathname
  488.     lea    dirname,a0
  489.     move.l    a0,d1
  490.     movea.l    (dosbase),a6
  491.     jsr    (_LVOFilePart,a6)
  492.     move.l    d0,(fileptr)
  493.  
  494. * If pathname is a volume name only, then FilePart()
  495. * returns pointer to the null byte after the :
  496. * To check if this is a volume, we check for the null byte
  497.     movea.l    d0,a0
  498.     tst.b    (a0)
  499.     bne.b    WriteDirName
  500.  
  501. * icon is a volume and dirname holds its name
  502.     lea    dirname,a0
  503.     move.l    a0,d0
  504.     bsr    WriteClip
  505.     tst.l    d0
  506.     beq    AbortClip
  507.     bra.b    nextarg
  508.  
  509. * icon is a directory and a0 points to its name
  510. WriteDirName
  511.     move.l    a0,d0
  512.     bsr    WriteClip
  513.     tst.l    d0
  514.     beq    AbortClip
  515.  
  516. nextarg    addq.l    #wa_SIZEOF,(arglist)
  517.     subq.l    #1,(numargs)
  518.     st    (separate)    ;flag to write separator before next icon
  519.     bra    WriteIconsToClip   ;loop back for next icon
  520.  
  521. callCloseClip
  522.     tst.l    (iff)
  523.     beq.b    NextAppMsg
  524.     bsr    CloseClip
  525.  
  526. NextAppMsg    movea.l    (appmsg),a1
  527.     movea.l    (execbase),a6
  528.     jsr    (_LVOReplyMsg,a6)
  529.     bra    HandleAppMsg    ;loop back for next appmsg
  530.  
  531.  
  532. AbortClip    tst.l    (iff)
  533.     beq    noiff
  534.     bsr    CloseClip
  535. noiff    movea.l    (intuibase),a6
  536.     moveq    #0,d0
  537.     jsr    (_LVODisplayBeep,a6)      ;warn that clipboard is not available
  538.     bra    NextAppMsg
  539.  
  540. endHandleAppMsg
  541.     rts
  542. ***** end HandleAppMsg
  543.  
  544.  
  545. ***** subroutine InitClip - opens IFF Clipboard
  546. * returns ptr to IFFHandle in d0 if successful
  547. InitClip    movea.l    (iffparsebase),a6
  548.     jsr    (_LVOAllocIFF,a6)
  549.     move.l    d0,(iff)
  550.     beq.b    noclip
  551.  
  552.     moveq    #0,d0
  553.     jsr    (_LVOOpenClipboard,a6)
  554.     movea.l    (iff),a0
  555.     move.l    d0,(iff_Stream,a0)
  556.     beq.b    noclip
  557.  
  558.     jsr    (_LVOInitIFFasClip,a6)
  559.  
  560.     movea.l    (iff),a0
  561.     moveq    #IFFF_WRITE,d0
  562.     jsr    (_LVOOpenIFF,a6)
  563.     bne.b    noclip
  564.  
  565.     movea.l    (iff),a0
  566.     move.l    #"FTXT",d0
  567.     move.l    #ID_FORM,d1
  568.     move.l    #IFFSIZE_UNKNOWN,D2
  569.     jsr    (_LVOPushChunk,a6)
  570.     bne.b    noclip
  571.  
  572.     movea.l    (iff),a0
  573.     moveq    #0,d0
  574.     move.l    #'CHRS',d1
  575.     move.l    #IFFSIZE_UNKNOWN,D2
  576.     jsr    (_LVOPushChunk,a6)
  577.     bne.b    noclip
  578.  
  579.     move.l    (iff),d0    ;return success
  580.     rts
  581.  
  582. noclip    moveq    #0,d0
  583.     rts
  584. ***** end InitClip
  585.  
  586.  
  587. ***** subroutine WriteClip - write name to Clipboard
  588. * receives address of text buffer in d0
  589. * returns 0 in d0 if failure
  590. WriteClip    push    d0    ;save ptr to buffer
  591.     bsr.b    strlen    ;returns length in d0
  592.     movea.l    (iff),a0
  593.     pop    a1    ;load ptr to buffer
  594.     push    d0    ;save string length
  595.     movea.l    (iffparsebase),a6
  596.     jsr    (_LVOWriteChunkBytes,a6)
  597.     cmp.l    (sp)+,d0    ;was write successful?
  598.     beq.b    WriteClipsuccess
  599.     moveq    #0,d0    ;return failure
  600.     rts
  601.  
  602. WriteClipsuccess
  603.     moveq    #1,d0
  604.     rts
  605. ***** end WriteClip
  606.  
  607.  
  608. ***** subroutine strlen - finds length of NULL-terminated string
  609. * receives address of string in d0
  610. * returns length in d0
  611. strlen    movea.l    d0,a0    ;put string addr in a0
  612.     moveq    #0,d0    ;clear d0
  613.     move.w    #-1,d0    ;set d0.w to maximum
  614.     move.l    d0,d1    ;set d1.w to maximum
  615. .loop    tst.b    (a0)+    ;test for null byte
  616.     dbeq    d1,.loop    ;loop back if not null
  617.  
  618.     sub.w    d1,d0    ;calculate length
  619.  
  620.     rts
  621. ***** end strlen
  622.  
  623. ***** subroutine CloseClip - closes IFF Clipboard
  624. CloseClip    movea.l    (iffparsebase),a6
  625.     movea.l    (iff),a0
  626.     jsr    (_LVOPopChunk,a6)  ;pops CHRS chunk
  627.  
  628.     movea.l    (iff),a0
  629.     jsr    (_LVOPopChunk,a6)  ;pops FORM chunk
  630.  
  631.     movea.l    (iff),a0
  632.     jsr    (_LVOCloseIFF,a6)
  633.  
  634.     movea.l    (iff),a0
  635.     movea.l    (iff_Stream,a0),a0
  636.     jsr    (_LVOCloseClipboard,a6)
  637.  
  638.     movea.l    (iff),a0
  639.     move.l    d0,(iff_Stream,a0)
  640.     jsr    (_LVOFreeIFF,a6)
  641.     rts
  642. ***** end CloseClip
  643.  
  644. ***** subroutine HandleGadget - processes Gadget events
  645. * returns 0 in d0 if user presses QUIT, else 1
  646.  
  647. HandleGadget
  648.     movea.l    (WindowMP),a0
  649.     movea.l    (gadtoolsbase),a6
  650.     jsr    (_LVOGT_GetIMsg,a6)
  651.     move.l    d0,(msg)
  652.     bne.b    gotmsg
  653.     moveq    #1,d0    ;non-QUIT code
  654.     rts
  655.  
  656. gotmsg    movea.l    d0,a1
  657.     move.l    (im_Class,a1),(class)
  658.     move.w    (im_Code,a1),(code)
  659.     move.l    (im_IAddress,a1),(gadget)
  660.  
  661.     jsr    (_LVOGT_ReplyIMsg,a6)
  662.  
  663.     cmpi.l    #IDCMP_REFRESHWINDOW,(class)
  664.     bne.b    testforgadget
  665.     movea.l    (I2CWnd),a0
  666.     jsr    (_LVOGT_BeginRefresh,a6)
  667.     movea.l    (I2CWnd),a0
  668.     moveq    #1,d0
  669.     jsr    (_LVOGT_EndRefresh,a6)
  670.     bra    HandleGadget
  671.  
  672. testforgadget
  673.     cmpi.l    #IDCMP_GADGETUP,(class)
  674.     bne    HandleGadget    ;this should never happen
  675.     movea.l    (gadget),a0
  676.     moveq    #0,d0
  677.     move.w    (gg_GadgetID,a0),d0
  678.     add.w    d0,d0    ;double to get word offset
  679.     move.w    (jumptable,pc,d0.w),d0
  680.     jmp    (jumptable,pc,d0.w)
  681.  
  682. jumptable    dw    pathgadevent-jumptable
  683.     dw    formatgadevent-jumptable
  684.     dw    quitgadevent-jumptable
  685.     dw    hidegadevent-jumptable
  686.  
  687. pathgadevent
  688.     tst.w    (code)
  689.     bne.b    setpathname
  690.     clr.l    (pathname)
  691.     bra    HandleGadget
  692.  
  693. setpathname    moveq    #1,d0
  694.     move.l    d0,(pathname)
  695.     bra    HandleGadget
  696.  
  697. formatgadevent
  698.     tst.w    (code)
  699.     bne.b    setcolumn
  700.     clr.l    (column)
  701.     bra    HandleGadget
  702.  
  703. setcolumn    moveq    #1,d0
  704.     move.l    d0,(column)
  705.     bra    HandleGadget
  706.  
  707. quitgadevent
  708.     moveq    #0,d0    ;quit code
  709.     rts
  710.  
  711. hidegadevent
  712.     bsr    CloseI2CWindow
  713.     bsr    CloseDownScreen
  714.     bra    HandleGadget
  715.  
  716. ***** end HandleGadget
  717.  
  718. initialSP    dl    0
  719. rc    dl    0
  720. WBenchMsg    dl    0
  721. execbase    dl    0
  722. dosbase    dl    0
  723. workbenchbase    dl    0
  724. intuibase    dl    0
  725. iffparsebase    dl    0
  726. gadtoolsbase    dl    0
  727. diskfontbase    dl    0
  728. gfxbase    dl    0
  729. iconbase    dl    0
  730. WorkbenchMP    dl    0
  731. WindowMP    dl    0
  732. appmenuitem    dl    0
  733. windowsignal    dl    0
  734. wbsignal    dl    0
  735. breaksignal    dl    $1000    ;CTRL-C
  736. allsignals    dl    0
  737. pathname    dl    0    ;\
  738. column    dl    0    ;- array for ReadArgs
  739. window    dl    0    ;/
  740. iff    dl    0
  741.  
  742. template    cstr    "PATHNAME/S,COLUMN/S,WINDOW/S"
  743. pathnamename
  744.     cstr    'PATHNAME'
  745. columnname    cstr    'COLUMN'
  746. windowname    cstr    'WINDOW'
  747.     even
  748.  
  749. * local vars for HandleAppMessage
  750. appmsg    dl    0
  751. arglist    dl    0
  752. numargs    dl    0
  753. fileptr    dl    0
  754. separate    db    0
  755. separator    cstr    ' '
  756. dirname    dcb.b    256,0
  757.     even
  758.  
  759. * local vars for HandleGadget
  760. msg    dl    0
  761. class    dl    0
  762. code    dw    0
  763. gadget    dl    0
  764.  
  765.     cstr    'By Douglas Nelson.  Freely distributable.'
  766.     cstr    '$VER: IconToClip 1.0 (23.1.93)'
  767. dosname    cstr    "dos.library"
  768. workbenchname    cstr    "workbench.library"
  769. intuitionname    cstr    "intuition.library"
  770. iffparsename    cstr    "iffparse.library"
  771. gadtoolsname    cstr    "gadtools.library"
  772. diskfontname    cstr    "diskfont.library"
  773. graphicsname    cstr    "graphics.library"
  774. iconname    cstr    "icon.library"
  775. menuname    cstr    'IconToClip'
  776.     even
  777.  
  778. *
  779. *  Original source machine generated by GadToolsBox V1.4
  780. *  which is (c) Copyright 1991,92 Jaba Development,
  781. *  then heavily altered to suit new assembly format,
  782. *  be shorter and clearer, and work for a window which is
  783. *  opened more than once.
  784. *
  785.  
  786. ***** subroutine SetupScreen
  787. * returns 1 in d0 if successful
  788. SetupScreen    lea    topaz8,a0
  789.     movea.l    diskfontbase,a6
  790.     jsr    (_LVOOpenDiskFont,a6)
  791.     move.l    d0,(Font)
  792.     bne.b    gotfont
  793.     rts        ;failure
  794.  
  795. gotfont    lea    ScreenName,a0
  796.     movea.l    (intuibase),a6
  797.     jsr    (_LVOLockPubScreen,a6)
  798.     move.l    d0,(Scr)
  799.     bne.b    gotpubscreen
  800.     rts        ;failure
  801.  
  802. gotpubscreen
  803.     movea.l    d0,a0
  804.     movea.l    #0,a1
  805.     movea.l    (gadtoolsbase),a6
  806.     jsr    (_LVOGetVisualInfoA,a6)
  807.     move.l    d0,(VisualInfo)
  808.     bne.b    gotvisinfo
  809.     rts        ;failure
  810.  
  811. gotvisinfo    moveq    #1,d0    ;success
  812.     rts
  813. ***** end SetupScreen
  814.  
  815. ***** subroutine CloseDownScreen
  816. CloseDownScreen
  817.     move.l    (VisualInfo),d0
  818.     beq.b    closescreen
  819.     movea.l    d0,a0
  820.     movea.l    (gadtoolsbase),a6
  821.     jsr    (_LVOFreeVisualInfo,a6)
  822.     move.l    #0,(VisualInfo)
  823.  
  824. closescreen
  825.     move.l    (Scr),d0
  826.     beq.b    closefont
  827.     movea.l    #0,a0
  828.     movea.l    d0,a1
  829.     movea.l    (intuibase),a6
  830.     jsr    (_LVOUnlockPubScreen,a6)
  831.     move.l    #0,(Scr)
  832.  
  833. closefont    move.l    (Font),d0
  834.     beq.b    endCloseDownScreen
  835.     movea.l    d0,a1
  836.     movea.l    (gfxbase),a6
  837.     jsr    (_LVOCloseFont,a6)
  838.  
  839. endCloseDownScreen
  840.     rts
  841. ***** end CloseDownScreen
  842.  
  843. ***** subroutine CloseI2CWindow
  844. CloseI2CWindow
  845.     move.l    (I2CWnd),d0
  846.     beq    nowindowopen
  847.     movea.l    d0,a2
  848.  
  849. * save window position
  850.     move.w    (wd_LeftEdge,a2),(I2CLeft)
  851.     move.w    (wd_TopEdge,a2),(I2CTop)
  852.  
  853. ClearGadgetMsgs
  854.     movea.l    (wd_UserPort,a2),a0
  855.     movea.l    (gadtoolsbase),a6
  856.     jsr    (_LVOGT_GetIMsg,a6)
  857.     tst.l    d0
  858.     beq.b    NoGadgetMsg
  859.  
  860.     movea.l    d0,a1
  861.     jsr    (_LVOGT_ReplyIMsg,a6)
  862.     bra.b    ClearGadgetMsgs
  863.  
  864. *end AppWindow Status
  865. NoGadgetMsg    movea.l    (I2CAppWindow),a0
  866.     cmpa.l    #0,a0
  867.     beq.b    NoAppWindow
  868.     movea.l    (workbenchbase),a6
  869.     jsr    (_LVORemoveAppWindow,a6)
  870.     moveq    #0,d0
  871.     move.l    d0,(I2CAppWindow)
  872.  
  873. * restore original windowMP (actually NULL)
  874. NoAppWindow    movea.l    (I2CWnd),a0
  875.     move.l    (olduserport),(wd_UserPort,a0)
  876.     movea.l    (intuibase),a6
  877.     jsr    (_LVOCloseWindow,a6)
  878.     moveq    #0,d0
  879.     move.l    d0,(I2CWnd)
  880.  
  881. * free gadget list
  882. nowindowopen
  883.     movea.l    (I2CGList),a0
  884.     cmpa.l    #0,a0
  885.     beq.b    NoGList
  886.     movea.l    (gadtoolsbase),a6
  887.     jsr    (_LVOFreeGadgets,a6)
  888.     moveq    #0,d0
  889.     move.l    d0,(I2CGList)
  890.  
  891. NoGList    rts
  892. ***** end CloseI2CWindow
  893.  
  894. ***** subroutine CreateGadgets
  895. * returns pointer to Gadget if successful
  896.  
  897. CreateGadgets
  898.     movea.l    (Scr),a0
  899.     moveq    #0,d2
  900.     move.b    (sc_WBorLeft,a0),d2
  901.     move.w    d2,(offx)
  902.  
  903. * offy = Scr.WBorTop + Scr.RastPort.TxHeight + 1
  904.     moveq    #0,d3
  905.     lea    (sc_RastPort,a0),a1    ;Screen contains RastPort
  906.     move.w    (rp_TxHeight,a1),d3
  907.     addq.w    #1,d3
  908.     moveq    #0,d0
  909.     move.b    (sc_WBorTop,a0),d0
  910.     add.w    d0,d3
  911.     move.w    d3,(offy)
  912.  
  913. * CreateContext
  914.     lea    I2CGList,a0
  915.     movea.l    (gadtoolsbase),a6
  916.     jsr    (_LVOCreateContext,a6)
  917.     move.l    d0,(gadlist)
  918.     beq    CreateGadgetFailure
  919.  
  920. *initialize NewGadgets
  921.     moveq    #3,d6
  922. gadloop    lea    I2CNGads,a0
  923.     move.l    d6,d1
  924.     mulu.w    #gng_SIZEOF,d1
  925.     adda.l    d1,a0
  926.     move.l    (VisualInfo),(gng_VisualInfo,a0)
  927.  
  928.     move.w    (offx),d1
  929.     add.w    d1,(gng_LeftEdge,a0)
  930.  
  931.     move.w    (offy),d1
  932.     add.w    d1,(gng_TopEdge,a0)
  933.  
  934.     dbra    d6,gadloop
  935.  
  936. * create gadgets
  937.     movea.l    (gadtoolsbase),a6
  938.     moveq    #CYCLE_KIND,d0
  939.     movea.l    (gadlist),a0
  940.     lea    I2CNGads0,a1
  941.     lea    I2CGTags0,a2
  942.     jsr    (_LVOCreateGadgetA,a6)
  943.     move.l    d0,(gadlist)
  944.     move.l    d0,(I2CGadgets0)
  945.  
  946.     moveq    #CYCLE_KIND,d0
  947.     movea.l    (gadlist),a0
  948.     lea    I2CNGads1,a1
  949.     lea    I2CGTags1,a2
  950.     jsr    (_LVOCreateGadgetA,a6)
  951.     move.l    d0,(gadlist)
  952.     move.l    d0,(I2CGadgets1)
  953.  
  954.     moveq    #BUTTON_KIND,d0
  955.     movea.l    (gadlist),a0
  956.     lea    I2CNGads2,a1
  957.     lea    I2CGTags2,a2
  958.     jsr    (_LVOCreateGadgetA,a6)
  959.     move.l    d0,(gadlist)
  960.     move.l    d0,(I2CGadgets2)
  961.  
  962.     moveq    #BUTTON_KIND,d0
  963.     movea.l    (gadlist),a0
  964.     lea    I2CNGads3,a1
  965.     lea    I2CGTags3,a2
  966.     jsr    (_LVOCreateGadgetA,a6)
  967.     move.l    d0,(gadlist)
  968.     move.l    d0,(I2CGadgets3)
  969.  
  970. *restore offsets in tags
  971.     moveq    #3,d6
  972. restoretags    lea    I2CNGads,a0
  973.     move.l    d6,d1
  974.     mulu.w    #gng_SIZEOF,d1
  975.     adda.l    d1,a0
  976.  
  977.     move.w    (offx),d1
  978.     sub.w    d1,(gng_LeftEdge,a0)
  979.  
  980.     move.w    (offy),d1
  981.     sub.w    d1,(gng_TopEdge,a0)
  982.     dbra    d6,restoretags
  983.  
  984.     tst.l    (gadlist)
  985.     beq.b    CreateGadgetFailure
  986.  
  987.     move.l    (I2CGList),d0
  988.     rts
  989.  
  990.  
  991. CreateGadgetFailure
  992.     moveq    #0,d0
  993.     rts
  994.  
  995. * local vars for CreateGadgets
  996. gadlist    dl    0
  997. offx    dw    0
  998. offy    dw    0    ;used in OpenI2CWindow
  999.  
  1000. ***** end CreateGadgets
  1001.  
  1002. ***** subroutine OpenI2CWindow
  1003. * returns ptr to Window in d0
  1004. OpenI2CWindow
  1005.     bsr    CreateGadgets
  1006.     tst.l    d0
  1007.     beq    winopenfail
  1008.  
  1009. * set window height
  1010.     moveq    #104,d0
  1011.     add.w    (offy),d0
  1012.     move.w    d0,(I2CHeight)
  1013.  
  1014. * open window
  1015.     suba.l    a0,a0
  1016.     lea    I2CWindowTags,a1
  1017.     movea.l    (intuibase),a6
  1018.     jsr    (_LVOOpenWindowTagList,a6)
  1019.     move.l    d0,(I2CWnd)
  1020.     beq    winopenfail
  1021.  
  1022. * must open window with no IDCMP flags so that no userport is created;
  1023. * we want to use custom port for user port
  1024.     movea.l    d0,a0
  1025.     move.l    (wd_UserPort,a0),(olduserport)    ; save UserPort
  1026.     move.l    (WindowMP),(wd_UserPort,a0)    ; set WindowMP
  1027.     move.l    #CYCLEIDCMP!BUTTONIDCMP!IDCMP_REFRESHWINDOW,d0
  1028.     jsr    (_LVOModifyIDCMP,a6)
  1029.  
  1030. * add gadget list
  1031.     movea.l    (I2CWnd),a0
  1032.     movea.l    (I2CGList),a1
  1033.     moveq    #0,d0
  1034.     move.l    #-1,d1
  1035.     suba.l    a2,a2
  1036.     jsr    (_LVOAddGList,a6)
  1037.  
  1038. * refresh gadgets
  1039.     movea.l    (I2CGList),a0
  1040.     movea.l    (I2CWnd),a1
  1041.     ; a2 is still 0
  1042.     jsr    (_LVORefreshGadgets,a6)
  1043.  
  1044. * set cycle gadgets to show current setting
  1045.     tst.l    (pathname)
  1046.     beq.b    testcol
  1047.     movea.l    (I2CGadgets0),a0
  1048.     movea.l    (I2CWnd),a1
  1049.     suba.l    a2,a2
  1050.     lea    gadtags,a3
  1051.     movea.l    (gadtoolsbase),a6
  1052.     jsr    (_LVOGT_SetGadgetAttrsA,a6)
  1053.  
  1054. testcol    tst.l    (column)
  1055.     beq.b    refreshwindow
  1056.     movea.l    (I2CGadgets1),a0
  1057.     movea.l    (I2CWnd),a1
  1058.     suba.l    a2,a2
  1059.     lea    gadtags,a3
  1060.     movea.l    (gadtoolsbase),a6
  1061.     jsr    (_LVOGT_SetGadgetAttrsA,a6)
  1062.  
  1063. refreshwindow
  1064.     movea.l    (I2CWnd),a0
  1065.     suba.l    a1,a1
  1066.     movea.l    (gadtoolsbase),a6
  1067.     jsr    (_LVOGT_RefreshWindow,a6)
  1068.  
  1069. * set up AppWindow
  1070.     moveq    #0,d0
  1071.     moveq    #0,d1
  1072.     movea.l    (I2CWnd),a0
  1073.     movea.l    (WorkbenchMP),a1
  1074.     suba.l    a3,a3
  1075.     movea.l    (workbenchbase),a6
  1076.     jsr    (_LVOAddAppWindowA,a6)
  1077.     move.l    d0,(I2CAppWindow)
  1078. * if this fails, it is not a problem
  1079.  
  1080.     move.l    (I2CWnd),d0
  1081.     rts
  1082.  
  1083. winopenfail    moveq    #0,d0
  1084.     rts
  1085.  
  1086. GD_PathGadget    EQU        0
  1087. GD_FormatGadget    EQU        1
  1088. GD_QuitGadget    EQU        2
  1089. GD_HideGadget    EQU        3
  1090.  
  1091. Scr    dl    0
  1092. VisualInfo    dl        0
  1093. I2CWnd    dl        0
  1094. I2CAppWindow    dl    0
  1095. olduserport    dl    0
  1096. I2CGList    dl        0
  1097. Font    dl        0
  1098.  
  1099. I2CNGads
  1100. I2CNGads0      dw        35,18,140,15
  1101.         dl        PathGadgetText,topaz8
  1102.         dw        GD_PathGadget
  1103.         dl        $0024,0,0
  1104.  
  1105. I2CNGads1    dw        35,58,140,15
  1106.         dl        FormatGadgetText,topaz8
  1107.         dw        GD_FormatGadget
  1108.         dl        $0024,0,0
  1109.  
  1110. I2CNGads2    dw        20,82,58,15
  1111.         dl        QuitGadgetText,topaz8
  1112.         dw        GD_QuitGadget
  1113.         dl        $0010,0,0
  1114.  
  1115. I2CNGads3    dw        124,82,58,15
  1116.         dl        HideGadgetText,topaz8
  1117.         dw        GD_HideGadget
  1118.         dl        $0010,0,0
  1119.  
  1120. I2CGTags
  1121. I2CGTags0    dl        GTCY_Labels,PathGadgetLabels
  1122.         dl        $00000000
  1123. I2CGTags1    dl        GTCY_Labels,FormatGadgetLabels
  1124.         dl        $00000000
  1125. I2CGTags2    dl        $00000000
  1126. I2CGTags3    dl        $00000000
  1127.  
  1128.  
  1129. PathGadgetText
  1130.     cstr        'Write to Clipboard'
  1131.  
  1132. FormatGadgetText
  1133.     cstr        'Write multiple names as'
  1134.  
  1135. QuitGadgetText
  1136.     cstr        'Quit'
  1137.  
  1138. HideGadgetText
  1139.     cstr        'Hide'
  1140.  
  1141.         even
  1142.  
  1143. PathGadgetLabels
  1144.     dl        PathGadgetLab0
  1145.         dl        PathGadgetLab1
  1146.         dl        0
  1147.  
  1148. FormatGadgetLabels
  1149.     dl        FormatGadgetLab0
  1150.         dl        FormatGadgetLab1
  1151.         dl        0
  1152.  
  1153. PathGadgetLab0    cstr        'Icon name only'
  1154. PathGadgetLab1    cstr        'Full pathname'
  1155.  
  1156. FormatGadgetLab0    cstr        'Row'
  1157. FormatGadgetLab1    cstr        'Column'
  1158.  
  1159. topazFName8    cstr        'topaz.font'
  1160.  
  1161.     even
  1162. topaz8    dl        topazFName8
  1163.         dw        8
  1164.         db        0,0
  1165.  
  1166. I2CGadgets0    dl    0
  1167. I2CGadgets1    dl    0
  1168. I2CGadgets2    dl    0
  1169. I2CGadgets3    dl    0
  1170.  
  1171. gadtags    dl    GTCY_Active,1
  1172.  
  1173. I2CWindowTags:
  1174. I2CL        dl        WA_Left
  1175.     dw    0    ;dummy word
  1176. I2CLeft    dw    0    ;store wd_LeftEdge here for tags
  1177. I2CT        dl        WA_Top
  1178.     dw    0    ;dummy word
  1179. I2CTop    dw    12    ;store wd_TopEdge here for tags
  1180. I2CW        dl        WA_Width,216
  1181. I2CH        dl        WA_Height
  1182.     dw    0
  1183. I2CHeight    dw    104
  1184.         dl        WA_Flags,$00000006    ;Flags
  1185.         dl        WA_Title,I2CWTitle
  1186.         dl        WA_ScreenTitle,I2CSTitle
  1187.         dl    WA_PubScreenName,ScreenName
  1188.         dl        $00000000
  1189.  
  1190. I2CWTitle    cstr        'IconToClip'
  1191.  
  1192. I2CSTitle     cstr        'IconToClip'
  1193. ScreenName    cstr    'Workbench'
  1194.  
  1195.     end
  1196.